/* 
 * http://www.sencha.com/learn/intro-to-panels/
 */
Ext.namespace('myApp.viewComponents.indexIndex');

myApp.viewComponents.indexIndex.timerId;

myApp.viewComponents.indexIndex.listPanel = new Ext.List({
    id:'linksList',
    store:myApp.stores.IndexLinks,
    itemTpl: new Ext.XTemplate(
        '<div>{controller}/{action} - <span id="{controller}-{action}" style="font-weight:bold;font-size:1.1em;">{[TophemanUtils.formatTime(values.timeElapsed)]}</span></div>'
    ),
    listeners:{
        itemtap:function(view,index,item,event){
            var record = myApp.stores.IndexLinks.getAt(index);
            Ext.dispatch({
                controller:record.data.controller,
                action:record.data.action,
                animation: {type: 'slide', direction: 'left'}
            })
        }
    }
})

myApp.views.indexIndex = Ext.extend(Ext.Panel, {
    fullscreen: true,
    layout:{
        type:'card',
        align:'stretch'
    },
    defaults:{
        dock:'top',
        style:'border-bottom:1px solid black;',
        flex:1
    },
    listeners:{
        activate:function(){
            console.log('activate');
            myApp.viewComponents.indexIndex.timerId = myApp.viewComponents.indexIndex.timerId = setInterval(function(){
                //console.log(TophemanUtils.formatTime(myApp.helpers.timer.getTimeElapsed()));
                Ext.get('Index-index').dom.innerHTML = TophemanUtils.formatTime(myApp.helpers.timer.getTimeElapsed());
            },100);
        },
        beforedeactivate:function(){
            console.log('beforedeactivate');
            clearInterval(myApp.viewComponents.indexIndex.timerId);
        }
    },
    dockedItems:[
        {
            xtype:'toolbar',
            title:'Sommaire',
            items:[
                {
                    xtype:'button',
                    text:'Reset',
                    handler:function(){
                        Ext.Msg.alert('Information', 'Fonctionnalité en cours de développement.', Ext.emptyFn);
                    }
                }
            ]
        }
    ],
    items:[myApp.viewComponents.indexIndex.listPanel],
    initComponent:function(){
        console.info('Index/Index.js - initComponent');
        myApp.helpers.Events.addTimerListenersToView(this,'Index', 'index');
        myApp.views.indexIndex.superclass.initComponent.apply(this,arguments);
    }
});
Ext.reg('indexIndex', myApp.views.indexIndex);
